package edu.pku.sei.mte.modification.command;

import java.util.LinkedList;
import java.util.List;

import edu.pku.sei.mte.mtemodel.model.MClass;
import edu.pku.sei.mte.mtemodel.model.MReference;

public class DeletingNodeCommand extends ModelModificationCommand{

	private MClass delNode;
	
	public MClass getDelNode() {
		return delNode;
	}

	public void setDelNode(MClass delNode) {
		this.delNode = delNode;
	}

	@Override
	public void execute() throws Exception {
		List<MClass> mcl = new LinkedList<MClass>();
		for(MClass c : delNode.getCompositeClass()){
			mcl.add(c);
		}
		while(!mcl.isEmpty()){
			removeNodeRequest(getModel(), mcl.get(0), getContext());
			mcl.remove(0);
		}
		List<MReference> mrl = new LinkedList<MReference>();
		for(MReference mr : delNode.getEdges()){
			mrl.add(mr);
			
		}
		while(!mrl.isEmpty()){
			removeEdgeRequest(getModel(), mrl.get(0), getContext());
			mrl.remove(0);
		}
		if(basicRemoveNode(delNode))
			commit();
	}

	@Override
	public void undo() {
		basicAddNode(delNode);
	}


}
